package com.flute.search.bean;

import java.util.ArrayList;
import java.util.List;

import com.flute.search.util.MyXppDriver;
import com.flute.search.util.XmlObjectUtil;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.converters.basic.DateConverter;

@XStreamAlias("fieldFilter")
public class FieldFilter {
	
	private List<FieldAlias> fieldAliases;

	public static FieldFilter fromXml(String xml) {
		XStream xstream = new XStream(new MyXppDriver());
		xstream.processAnnotations(FieldFilter.class);
		xstream.registerConverter(new DateConverter());
		return (FieldFilter)xstream.fromXML(xml);
	}
	
	public List<Field> getFieldsByAlias(String alias){
		if(fieldAliases == null){
			return null;
		}
		for(FieldAlias fieldAlias : fieldAliases){
			if(alias.equals(fieldAlias.getAlias())){
				return fieldAlias.getFields();
			}
		}
		return null;
	}
	
	public static void main(String[] args) {
		FieldFilter ff = new FieldFilter();
		Field f = new Field();
		f.setName("ss");
		List<Field> l = new ArrayList<Field>();
		l.add(f);
//		ff.setAlbum(l);
		System.out.println(XmlObjectUtil.toXml(ff));
	}

	public List<FieldAlias> getFieldAliases() {
		return fieldAliases;
	}

	public void setFieldAliases(List<FieldAlias> fieldAliases) {
		this.fieldAliases = fieldAliases;
	}
}
